﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;

namespace MyCommon.Configuration
{
    /// <summary>
    /// 密码重写节
    /// </summary>
    public class PasswordOverwriteSection : ConfigurationSection
    {
        /// <summary>
        /// 是否起用
        /// </summary>
        [ConfigurationProperty("isEnable", DefaultValue = true)]
        public bool IsEnable
        {
            get { return (bool)this["isEnable"]; }
            set { this["isEnable"] = value; }
        }

        /// <summary>
        /// 用户名密码组的集体
        /// </summary>
        [ConfigurationProperty("settings", IsDefaultCollection = true)]
        [ConfigurationCollection(typeof(SampleSettings), AddItemName = "add")]
        public ConfigurationSettingsCollection<UserSettings> Settings
        {
            get
            {
                return (ConfigurationSettingsCollection<UserSettings>)this["settings"];
            }
        }
    }
    /// <summary>
    /// 配置文件SettingsCollection中的项 --郭旭东
    /// </summary>
    [ConfigurationSettingsKey("UserName")]
    public class UserSettings : ConfigurationElement
    {
        /// <summary>
        /// 构造UserSettings
        /// </summary>
        public UserSettings()
        {
        }
        /// <summary>
        /// 构造UserSettings
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <param name="password">密码</param>
        public UserSettings(string userName, string password)
            : this()
        {
            UserName = userName;
            Password = password;
        }
        /// <summary>
        /// 构造UserSettings
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <param name="password">密码</param>
        /// <param name="fullName">全名</param>
        /// <param name="idCardNum">身份证号</param>
        public UserSettings(string userName, string password, string fullName, string idCardNum)
            : this(userName,password)
        {
            FullName = fullName;
            IdCardNum = idCardNum;
        }
        /// <summary>
        /// 用户名
        /// </summary>
        [ConfigurationProperty("userName", DefaultValue = "Admin")]
        [StringValidator(MinLength = 1)]
        public string UserName
        {
            get { return (string)this["userName"]; }
            set { this["userName"] = value; }
        }
        /// <summary>
        /// 密码
        /// </summary>
        [ConfigurationProperty("password")]
        [StringValidator]
        public string Password
        {
            get { return (string)this["password"]; }
            set { this["password"] = value; }
        }
        /// <summary>
        /// 全名
        /// </summary>
        [ConfigurationProperty("fullName")]
        [StringValidator]
        public string FullName
        {
            get { return (string)this["fullName"]; }
            set { this["fullName"] = value; }
        }
        /// <summary>
        /// 身份证号
        /// </summary>
        [ConfigurationProperty("idCardNum")]
        [StringValidator]
        public string IdCardNum
        {
            get { return (string)this["idCardNum"]; }
            set { this["idCardNum"] = value; }
        }
    }
}
